package oracle.apps.financials.collection.po;

import android.R.color;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.cyrilmottier.android.greendroid.R;

public class DetailItemView extends SubtextItemView {

	protected ImageView imageView;

	public DetailItem item;

	public Drawable backgroud;

	public DetailItemView(Context context) {
		this(context, null);
	}

	public DetailItemView(Context context, AttributeSet attrs) {
		super(context, attrs);

	}

	public void prepareItemView() {
		super.prepareItemView();
		imageView = (ImageView) findViewById(R.id.row_arrow);
		backgroud = this.getBackground();
	}

	public void setObject(Item object) {

		item = (DetailItem) object;
		if (mTextView != null) {
			mTextView.setText(item.text);
		}
		if (mSubtextView != null) {
			mSubtextView.setText(item.subtext);
		}
		if (this.imageView != null) {
			if (!item.isShowDetailButton) {
				this.imageView.setVisibility(INVISIBLE);
			} else {
				if (item.isHighlight()) {
					setHighlight(this);
				} else {
					setBackgroundDrawable(backgroud);
				}
				if (item.onClickListener != null) {
					this.imageView.setOnClickListener(item.onClickListener);

				}
			}
		}
		if (item.textColor!= color.black) {
			mSubtextView.setTextColor(item.textColor);
			mTextView.setTextColor(item.textColor);
		}

	}

	void setHighlight(ViewGroup viewGroup) {
		// GradientDrawable gd = new
		// GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] {
		// 0xFF616261, 0xFF131313 });
		GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { 0xFF4F99F6, Color.BLUE });
		gd.setCornerRadius(0f);
		viewGroup.setBackgroundDrawable(gd);
	}
}
